package com.ruoyi.repair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.repair.domain.EquipmentRepair;
import com.ruoyi.repair.service.IEquipmentRepairService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备维修记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-03
 */
@RestController
@RequestMapping("/repair/repair")
public class EquipmentRepairController extends BaseController
{
    @Autowired
    private IEquipmentRepairService equipmentRepairService;

    /**
     * 查询设备维修记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EquipmentRepair equipmentRepair)
    {
        startPage();
        List<EquipmentRepair> list = equipmentRepairService.selectEquipmentRepairList(equipmentRepair);
        return getDataTable(list);
    }

    /**
     * 导出设备维修记录列表
     */
    @Log(title = "设备维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentRepair equipmentRepair)
    {
        List<EquipmentRepair> list = equipmentRepairService.selectEquipmentRepairList(equipmentRepair);
        ExcelUtil<EquipmentRepair> util = new ExcelUtil<EquipmentRepair>(EquipmentRepair.class);
        util.exportExcel(response, list, "设备维修记录数据");
    }

    /**
     * 获取设备维修记录详细信息
     */
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") String repairId)
    {
        return success(equipmentRepairService.selectEquipmentRepairByRepairId(repairId));
    }

    /**
     * 新增设备维修记录
     */
    @Log(title = "设备维修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentRepair equipmentRepair)
    {
        return toAjax(equipmentRepairService.insertEquipmentRepair(equipmentRepair));
    }

    /**
     * 修改设备维修记录
     */
    @Log(title = "设备维修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentRepair equipmentRepair)
    {
        return toAjax(equipmentRepairService.updateEquipmentRepair(equipmentRepair));
    }

    /**
     * 删除设备维修记录
     */
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable String[] repairIds)
    {
        return toAjax(equipmentRepairService.deleteEquipmentRepairByRepairIds(repairIds));
    }

    @Log(title = "设备维修记录", businessType = BusinessType.INSERT)
    @PostMapping("/repairEquipment")
    public AjaxResult repairEquipment(@RequestBody EquipmentRepair equipmentRepair)
    {
        return toAjax(equipmentRepairService.repairEquipment(equipmentRepair));
    }
}
